App.controller('bookingController', ['$rootScope', '$scope', '$state', '$window', 'Page',function($rootScope, $scope, $state, $window, Page) {
		$scope.lineId = $state.params.lineId;
		$scope.planStatus = $state.params.planStatus;
		
		$scope.booking = {};
		
	 	$scope.lineStop = {
			mapContainer : 'lineMap',
			defaultWeidu : 30.595444,
            defaultJingdu : 114.296308,
			init : function(stops){
				$("#" + this.mapContainer).empty();
				$scope.lineStop.map = new AMap.Map(this.mapContainer, {
					zoomEnable: false,
                    center: [this.defaultJingdu,this.defaultWeidu],
                    features : ['bg','road']
                });
				$scope.lineStop.path = [];
				$(stops).each(function(idx, stop) {
                    if(stop.weidu && stop.jingdu){
                        $scope.lineStop.path.push([stop.jingdu,stop.weidu]);
                    }
                });
				
				var section = {};
				AMap.service(["AMap.PolyEditor"], function() {
                    section.line =(function(){
                        return new AMap.Polyline({
                            map: $scope.lineStop.map,
                            path: $scope.lineStop.path,
                            strokeColor: "#FF33FF",//线颜色
                            strokeOpacity: 1,//线透明度
                            strokeWeight: 3,//线宽
                            strokeStyle: "solid",//线样式
                            showDir:true,
                            lineJoin:'round'
                        });
                    })();
                });
				$(stops).each(function(idx, stop) {
                    if(stop.weidu && stop.jingdu && stop.stopType != '0'){
                        $scope.lineStop.createStopMarker(stop);
                    }
                });
				 $scope.lineStop.map.setFitView();
			},
			createStopMarker : function(stop){
                 var content = '<img src="./img/icon/' + ( stop.stopType == '1' ? 'up_icon.png' : 'down_icon.png' ) + '" style="width:18px;height:30px;"></img>'
					 + '<div style="font-weight:bold;color:#ff0000;width:18px;font-size:12px;line-height:14px;text-align:center;">' + stop.stopName + '</div>';
	                 return new AMap.Marker({
	                        position: [stop.jingdu,stop.weidu],
	                        map: $scope.lineStop.map,
	                        offset : new AMap.Pixel(-9,-30),
	                        zIndex: 1100,
	                        content : content
	                 });
           	}
		};
	 	
	 	Page.ajaxPost('line/detail.do',{lineId: $scope.lineId,planStatus: $scope.planStatus},function(resp){
	 		$scope.booking = {
	 			line : resp.data
	 		};
	 		Page.ajaxPostQuiet('line/stops.do',{lineId : $scope.lineId},function(resp){
		 		$scope.lineStop.init(resp.data);
		 		$scope.booking.line.stops = resp.data;
			});
	 		$state.go('booking.plan');
		});
}]);